#!/bin/bash
# **********************************************************
# * Author        : GIN
# * Email         : ginvip@qq.com
# * Create time   : 2024-11-25 22:08
# * Filename      : create_account.sh
# * Description   : 该脚本用于批量生成以太坊账户与对应的私钥
# **********************************************************
: <<'NOTE'
这里是注释
geth版本为1.6.7, 与 pow and poa 容器中的geth版本对应
NOTE
# 要生的账号数量 
NUM_ACCOUNTS=499
# POW的密码文件
PASSWORD_FILE="/data/eth_project/ethpow/standalone/data/config/password"
CMD=${PWD}/bin/geth
# POW的 gensis.json 模板文件
FILE=${PWD}/template/template_pow_genesis.json
# 保存数据目录
DATADIR=${PWD}/data

function generate() {
    [ -d ${PWD}/data/keystore ] && rm -rf ${PWD}/data/*
    cat ${FILE} > ${PWD}/template/genesis.json
    # 创建账户并保存地址
    for i in $(seq 1 $NUM_ACCOUNTS)
    do
      echo "创建第 $i 个账户..."
      account=`${CMD} account new --datadir $DATADIR --password $PASSWORD_FILE |awk -F '[{}]' '{print $2}'`
      echo "添加第 $i 个账户 $account 到文件中..."
      sed -i "/alloc/a    \"${account}\": {\n        \"balance\": \"0x200000000000000000000000000000000000000000000000000000000000000\"\n}," ${PWD}/template/genesis.json
    done
    jq . ${PWD}/template/genesis.json > ${PWD}/template/new_genesis.json
}

generate

# jq . ./genesis.json > /data/nfsdata/ethpoa/config/genesis.json
# /bin/cp -r ./data/keystore /data/nfsdata/ethpoa/config/
# /data/nfsdata/geth167/geth init --datadir /data/nfsdata/ethpoa/node0 /data/nfsdata/ethpoa/config/genesis.json
# /bin/cp -r /data/nfsdata/geth167/data/keystore /data/nfsdata/ethpoa/node0/

# 查看生成的账户
#ARR=(`${CMD} account list --datadir $DATADIR | awk -F - '{print $NF}'`)


#for (( i=0;i<${#ARR[@]};i++ ))
#do
  #echo ${ARR[i]}
#  sed -i "/alloc/a    \"${ARR[i]}\": {\n        \"balance\": \"0x200000000000000000000000000000000000000000000000000000000000000\"\n}," ./genesis.json
#done


















